package com.ymatou.iapi.dguser.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.CreateUserBackBean;
import com.ymatou.iapi.dguser.service.CreateUserBackCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.database.model.DGThirdPartyBindInfo;
import com.ymttest.database.model.DGUserExtInfo;
import com.ymttest.database.model.DGUserInfo;
import com.ymttest.database.model.DGWxUnionidBindInfo;
import com.ymttest.database.sqlwapper.DGUserWapper;
import com.ymttest.utils.TestDataManager;
/**
*后台创建用户Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_CreateUserBack{
	private static CreateUserBackBean createuserbackBean;
	private static CreateUserBackCall createuserbackCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("后台创建用户Test");
	}

	@Before
	public void caseUp() {
		createuserbackBean=new CreateUserBackBean();
		createuserbackCall=new CreateUserBackCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(createuserbackCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateUserBack_001() {
		Logger.start(true,"正确数据，成功");
		try {
			createuserbackBean = DGUserCallService.initUsercreateNewBean();
			createuserbackCall.setData(createuserbackBean);
			createuserbackCall.callService();			
			Logger.verifyEquals("true", createuserbackCall.getString("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateUserBack_002() {
		Logger.start(true,"手机号为空,失败");
		try {
			createuserbackBean = DGUserCallService.initUsercreateNewBean();
			createuserbackBean.setMobile(null);
			createuserbackCall.setData(createuserbackBean);
			createuserbackCall.callService();			
			Logger.verifyEquals("false", createuserbackCall.getString("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateUserBack_003() {
		Logger.start(true,"买家区号为空,成功");
		try {
			createuserbackBean = DGUserCallService.initUsercreateNewBean();
			createuserbackBean.setMobileAreaCode(null);
			createuserbackCall.setData(createuserbackBean);
			createuserbackCall.callService();			
			Logger.verifyEquals("false", createuserbackCall.getString("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateUserBack_004() {
		Logger.start(true,"卖家区号为空，失败");
		try {
			createuserbackBean = DGUserCallService.initUsercreateNewBean();
			createuserbackBean.setMobileAreaCode(null);
			createuserbackBean.setUserType(1);
			createuserbackCall.setData(createuserbackBean);
			createuserbackCall.callService();			
			Logger.verifyEquals("false", createuserbackCall.getString("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateUserBack_005() {
		Logger.start(true,"买家手机号重复");
		try {
			createuserbackBean = DGUserCallService.initUsercreateNewBean();
			createuserbackCall.setData(createuserbackBean);
			createuserbackCall.callService();
			Logger.verifyEquals("true", createuserbackCall.getString("success"), "验证success");
			
			CreateUserBackBean createuserbackBean1 = DGUserCallService.initUsercreateNewBean();
			createuserbackBean1.setMobile(createuserbackBean.getMobile());
//			
//			createuserbackCall.setData(createuserbackBean1);
//			createuserbackCall.callService();			
//			Logger.verifyEquals("false", createuserbackCall.getString("success"), "验证success");
//			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateUserBack_006() {
		Logger.start(true,"登录密码为空");
		try {
			createuserbackBean = DGUserCallService.initUsercreateNewBean();
			createuserbackBean.setLoginPwd(null);
			createuserbackCall.setData(createuserbackBean);
			createuserbackCall.callService();			
			Logger.verifyEquals("false", createuserbackCall.getString("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateUserBack_007() {
		Logger.start(true,"登录密码弱密码");
		try {
			createuserbackBean = DGUserCallService.initUsercreateNewBean();
			createuserbackBean.setLoginPwd("123");
			createuserbackCall.setData(createuserbackBean);
			createuserbackCall.callService();			
			Logger.verifyEquals("false", createuserbackCall.getString("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		} 
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateUserBack_0071() {
		Logger.start(true,"六位纯数字，失败");
		try {
			createuserbackBean = DGUserCallService.initUsercreateNewBean();
			createuserbackBean.setLoginPwd("123123");
			createuserbackCall.setData(createuserbackBean);
			createuserbackCall.callService();			
			Logger.verifyEquals("false", createuserbackCall.getString("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		} 
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateUserBack_0072() {
		Logger.start(true,"六位数字字母混合，成功");
		try {
			createuserbackBean = DGUserCallService.initUsercreateNewBean();
			createuserbackBean.setLoginPwd("123aaa");
			createuserbackCall.setData(createuserbackBean);
			createuserbackCall.callService();			
			Logger.verifyEquals("true", createuserbackCall.getString("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		} 
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateUserBack_0073() {
		Logger.start(true,"6-9特殊字符，失败");
		try {
			createuserbackBean = DGUserCallService.initUsercreateNewBean();
			createuserbackBean.setLoginPwd("123aaa3 ");
			createuserbackCall.setData(createuserbackBean);
			createuserbackCall.callService();			
			Logger.verifyEquals("false", createuserbackCall.getString("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		} 
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateUserBack_0074() {
		Logger.start(true,"六到九正确，成功");
		try {
			createuserbackBean = DGUserCallService.initUsercreateNewBean();
			createuserbackBean.setLoginPwd("123123as");
			createuserbackCall.setData(createuserbackBean);
			createuserbackCall.callService();			
			Logger.verifyEquals("true", createuserbackCall.getString("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		} 
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateUserBack_0075() {
		Logger.start(true,"九位纯数字，失败");
		try {
			createuserbackBean = DGUserCallService.initUsercreateNewBean();
			createuserbackBean.setLoginPwd("123123123");
			createuserbackCall.setData(createuserbackBean);
			createuserbackCall.callService();			
			Logger.verifyEquals("false", createuserbackCall.getString("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		} 
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateUserBack_0076() {
		Logger.start(true,"九位纯字母，失败");
		try {
			createuserbackBean = DGUserCallService.initUsercreateNewBean();
			createuserbackBean.setLoginPwd("asdasdasd");
			createuserbackCall.setData(createuserbackBean);
			createuserbackCall.callService();			
			Logger.verifyEquals("false", createuserbackCall.getString("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		} 
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateUserBack_0077() {
		Logger.start(true,"九位混合，成功");
		try {
			createuserbackBean = DGUserCallService.initUsercreateNewBean();
			createuserbackBean.setLoginPwd("123asd123");
			createuserbackCall.setData(createuserbackBean);
			createuserbackCall.callService();			
			Logger.verifyEquals("true", createuserbackCall.getString("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateUserBack_0078() {
		Logger.start(true,"超过九位，失败");
		try {
			createuserbackBean = DGUserCallService.initUsercreateNewBean();
			createuserbackBean.setLoginPwd("123123123a");
			createuserbackCall.setData(createuserbackBean);
			createuserbackCall.callService();			
			Logger.verifyEquals("false", createuserbackCall.getString("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		} 
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateUserBack_008() {
		Logger.start(true,"用户类型错误");
		try {
			createuserbackBean = DGUserCallService.initUsercreateNewBean();
			createuserbackBean.setUserType(3);
			createuserbackCall.setData(createuserbackBean);
			createuserbackCall.callService();			
			Logger.verifyEquals("true", createuserbackCall.getString("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateUserBack_009() {
		Logger.start(true,"国家编号错误");
		try {
			createuserbackBean = DGUserCallService.initUsercreateNewBean();
			createuserbackBean.setCountryCode("123141122");
			createuserbackCall.setData(createuserbackBean);
			createuserbackCall.callService();			
			Logger.verifyEquals("true", createuserbackCall.getString("success"), "验证success");
		} catch (Exception e) { 
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateUserBack_010() {
		Logger.start(true,"渠道来源错误，失败");
		try {
			createuserbackBean = DGUserCallService.initUsercreateNewBean();
			createuserbackBean.setCountryCode("123141122");
			createuserbackCall.setData(createuserbackBean);
			createuserbackCall.callService();			
			Logger.verifyEquals("true", createuserbackCall.getString("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test 
	@Category({P1.class})
	@TestCase
	public void Tc_CreateUserBack_011() {
		Logger.start(true,"终端来源错误，失败");
		try {
			createuserbackBean = DGUserCallService.initUsercreateNewBean();
			createuserbackBean.setChannelSource(12313);
			createuserbackCall.setData(createuserbackBean);
			createuserbackCall.callService();			
			Logger.verifyEquals("true", createuserbackCall.getString("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateUserBack_012() {
		Logger.start(true,"应用来源错误，失败");
		try {
			createuserbackBean = DGUserCallService.initUsercreateNewBean();
			createuserbackBean.setTerminalSource(1231313);
			createuserbackCall.setData(createuserbackBean);
			createuserbackCall.callService();			
			Logger.verifyEquals("true", createuserbackCall.getString("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class}) 
	@TestCase
	public void Tc_CreateUserBack_013() {
		Logger.start(true,"微信appid为空");
		try {
			createuserbackBean = DGUserCallService.initUsercreateNewBean();
			createuserbackBean.setWxAppId(null);
			createuserbackCall.setData(createuserbackBean);
			createuserbackCall.callService();			
			Logger.verifyEquals("true", createuserbackCall.getString("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateUserBack_014() {
		Logger.start(true,"secret为空，失败");
		try {
			createuserbackBean = DGUserCallService.initUsercreateNewBean();
			createuserbackBean.setSecret(null);
			createuserbackCall.setData(createuserbackBean);
			createuserbackCall.callService();			
			Logger.verifyEquals("true", createuserbackCall.getString("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase 
	public void Tc_CreateUserBack_015() {
		Logger.start(true,"同一数据，连续创建");
		try {
			createuserbackBean = DGUserCallService.initUsercreateNewBean();
			createuserbackCall.setData(createuserbackBean);
			for (int i = 0; i < 10; i++) {
				createuserbackCall.callService();
				Logger.verifyEquals("true", createuserbackCall.getString("success"), "验证success");
			}
			
		} catch (Exception e) {
			Logger.fail(e); 
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateUserBack_016() {
		Logger.start(true,"创建分销员，成功");
		try {
			createuserbackBean = DGUserCallService.initUsercreateNewBean();
			createuserbackBean.setUserType(3);
			createuserbackCall.setData(createuserbackBean);
			createuserbackCall.callService();			
			Logger.verifyEquals("true", createuserbackCall.getString("success"), "验证success");
			verifyDB(createuserbackBean, Integer.valueOf(createuserbackCall.getString("userId")));
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	private void verifyDB(CreateUserBackBean usercreateBean2, Integer uid) {
		Logger.comment("验证DGUserInfo");
		DGUserWapper DGUserWapper=new DGUserWapper();
		DGUserInfo uinfo = DGUserWapper.selectDGUserInfo(uid).get(0);
		Logger.verifyNotNull(uinfo.getLoginPwd(), "验证LoginPwd");
		if (usercreateBean2.getMobile() != null) {
			Logger.verifyEquals(usercreateBean2.getMobile(), uinfo.getMobile(), "验证Mobile");
		}
		if (usercreateBean2.getMobileAreaCode() != null) {
			Logger.verifyEquals(usercreateBean2.getMobileAreaCode(), uinfo.getMobileAreaCode(), "验证MobileAreaCode");
		}
		Logger.verifyEquals(0, uinfo.getUserStatus(), "验证UserStatus");
		Logger.comment("验证DGUserExtInfo");
		DGUserExtInfo exinfo = DGUserWapper.selectDGUserExtInfo(uid).get(0);
		Logger.verifyEquals(usercreateBean2.getAppSource(), exinfo.getAppSource(), "验证AppSource");
		Logger.verifyEquals(usercreateBean2.getCountryCode(), exinfo.getCountryCode(), "验证CountryCode");
		
	}
}